package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.flow.cmdb;


import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.cmdb.FlowFormPartIn;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhengyr
 */
@Repository
public interface FlowFormPartInRepo extends JpaRepository<FlowFormPartIn, Long>, JpaSpecificationExecutor<FlowFormPartIn> {
    /**
     * 根据流程Id检索表单
     */
    FlowFormPartIn findByProcessId(String processId);
    List<FlowFormPartIn> findAllByProcessId(String processId);

    @Query(value = "select distinct i.* from t_gw_flow_form_part_in_detail d" +
            " left join t_gw_flow_form_part_in i on d.process_id = i.process_id  where i.is_close = 0 and d.sn = :sn  ", nativeQuery = true)
    List<FlowFormPartIn> findFlowPartSn(String sn);

    @Query(value = "select distinct i.* from t_gw_flow_form_cpu_in_detail d" +
            " left join t_gw_flow_form_part_in i on d.process_id = i.process_id  where i.is_close = 0 and d.sn = :sn  ", nativeQuery = true)
    List<FlowFormPartIn> findFlowCpuSn(String sn);

    @Query(value = "select distinct i.* from t_gw_flow_form_disk_in_detail d" +
            " left join t_gw_flow_form_part_in i on d.process_id = i.process_id  where i.is_close = 0 and d.sn = :sn  ", nativeQuery = true)
    List<FlowFormPartIn> findFlowDiskSn(String sn);

    @Query(value = "select distinct i.* from t_gw_flow_form_memory_in_detail d" +
            " left join t_gw_flow_form_part_in i on d.process_id = i.process_id  where i.is_close = 0 and d.sn = :sn  ", nativeQuery = true)
    List<FlowFormPartIn> findFlowMemorySn(String sn);
}
